package fw.qaz.asmx.reader.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import fw.qaz.asmx.reader.R;
import fw.qaz.asmx.reader.adapter.item.BookItem;

import java.util.ArrayList;

public class BookListAdapter
{
    BookArrayAdapter adapter;                             //书架adapter
    ArrayList<BookItem> books = new ArrayList<>();

    //加书接口
    public void addBookToShelf(String name,String imagePath,String path,int ReadProgress){
        BookItem book =new BookItem(name,imagePath,path,ReadProgress);//新建书类
        /*
        * 以后可能会在这里检查
        * */
        books.add(book);
    }

    //测试函数getdata
    private void getData()
    {
        addBookToShelf("qaz","图片","第一本书的路径",21);
        addBookToShelf("mao","图片","mao的路径",0);
        addBookToShelf("你好安卓","图片2","第2本书的路径",45);
        /*
        for(int i=0;i<100;i++){
            addBookToShelf("第"+i+"本书","第"+i+"图的路径","第"+i+"本书的路径",Float.valueOf(i));
        }
        */
    }

    public BookListAdapter(@NonNull Context context)
    {
        getData();//获取数据源
        adapter  = new BookArrayAdapter(
                context,
                R.layout.list_book_item,
                books
        );
    }

    public BookArrayAdapter getAdapter()
    {
        return adapter;
    }
    public ArrayList<BookItem> getBooks()
    {
        return books;
    }

    //用于更新数据源
    public void setBooks(ArrayList<BookItem> books)
    {
        this.books.clear();
        this.books.addAll(books);
    }
}